/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

/**
 *
 * @author WilliamCheng
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import client.*;
import static client.SimpleClient.noteList;
import data.Note;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class test extends JFrame implements ActionListener {

    JLabel lb = new JLabel("新建笔记");
    JButton bt = new JButton("新建");
    JTextField tf = new JTextField(20);
    //建立指定列数的文本框
    JTextArea ta = new JTextArea(10, 20);
    JScrollPane scroll; 
JPanel pan; //用此pan来添加图片，然后把它放入主窗口。 


    //建立一个指定行数和列数的空的JTextArea

    public test() {
        super("笔记菜单栏");
        //JFrame(String title) Creates a new, 
        //initially invisible Frame with the specified title.
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        c.add(lb);
        c.add(ta);
        c.add(bt);
        c.add(tf);
        pan = new JPanel(); 
pan.setLayout(new FlowLayout()); 
scroll = new JScrollPane(pan); 
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);//设置何时显示滚动条 
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); //设置何时显示滚动条 
Container container = getContentPane(); 
container.add(scroll); 

        bt.addActionListener(this);
        tf.addActionListener(this);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(200, 100);
        setVisible(true);
        JFrame.setDefaultLookAndFeelDecorated(true);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == bt) {
            ta.append("现在按下按钮引发的事件\n");
            try {
                
                SimpleClient client = new SimpleClient();
                client.testClient();
                for (Note note : noteList) {
                    ta.append(note.title + "\n");
                    ta.append(note.content + "\n");
                }
            } catch (Exception ex) {
                System.out.println("test client err!");
            }
        } else {
            try{
                for (Note note : noteList) {
                    ta.append("现在为按下文本框和回车键引发的响应");
                    ta.append(note.content + "\n");
                }
            }
            catch (Exception ex) {
                System.out.println("test client err!");
            }
        }
    }

    public static void main(String[] args) {
        new test();
    }
}
